package cn.itcast.search.mq;

import cn.itcast.search.mqconstans.MqConstants;
import cn.itcast.search.service.SearchService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class HotelListener {

    @Autowired
    private SearchService searchService;

    /**
     * 监听酒店新增或修改的业务
     * @param id 酒店id
     */
    @RabbitListener(bindings = @QueueBinding(
            value=@Queue("item.insert.queue"),
            exchange = @Exchange(value = "item.topic",type = ExchangeTypes.TOPIC),
            key = "item.insert"
    ))
    public void listenItemInsertOrUpdate(Long id){
        searchService.insertById(id);
    }

    /**
     * 监听酒店删除的业务
     * @param id 酒店id
     */
    @RabbitListener(bindings = @QueueBinding(
            value=@Queue("item.delete.queue"),
            exchange = @Exchange(value = "item.topic",type = ExchangeTypes.TOPIC),
            key = "item.delete"
    ))
    public void listenItemDelete(Long id){
        searchService.deleteById(id);
    }
}